# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=nlopt
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.6.2
pkgrel=1
pkgdesc="A library for nonlinear optimization (mingw-w64)"
arch=('any')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python3-numpy"
             "${MINGW_PACKAGE_PREFIX}-swig")
url='https://nlopt.readthedocs.io/en/latest/'
license=('LGPLv2.1+')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/stevengj/nlopt/archive/v${pkgver}.tar.gz")
sha256sums=('cfa5981736dd60d0109c534984c4e13c615314d3584cf1c392a155bfe1a3b17e')
noextract=(${_realname}-${pkgver}.tar.gz)

prepare () {
  [[ -d ${srcdir}/${_realname}-${pkgver} ]] && rm -rf ${srcdir}/${_realname}-${pkgver}
  tar -xzf ${srcdir}/${_realname}-${pkgver}.tar.gz -C $srcdir || true
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  "${MINGW_PREFIX}/bin/cmake.exe" -Wno-dev \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DPYTHON_EXECUTABLE="${MINGW_PREFIX}/bin/python3" \
    -DBUILD_SHARED_LIBS=ON \
    -DNLOPT_PYTHON=ON \
    -DNLOPT_SWIG=ON \
    -DNLOPT_GUILE=OFF \
    ../${_realname}-${pkgver}

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check || true
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR="${pkgdir}" install
}
